package com.shopping.adminServlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.shopping.bean.Review;
import com.shopping.service.AdminService;
import com.shopping.service.impl.AdminServiceImpl;

/**
 * @author 216
 * 后台更改或删除评论
 *
 */
@WebServlet("/updateReview.do")
public class AdminServletUpdateReview extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String keyword = null;
		String content = null;
		int rId = 0;
		if(req.getParameter("keyword") != null) {
			keyword = req.getParameter("keyword");
		}
		if(req.getParameter("content") != null) {
			content = req.getParameter("content");
		}
		if(req.getParameter("rId") != null) {
			rId = Integer.parseInt(req.getParameter("rId"));
		}
		AdminService as = new AdminServiceImpl();
		Review newReview = new Review();
		newReview.setrContent(content);
		Review oldReview = new Review();
		oldReview.setrId(rId);
		if(keyword.equals("删除")) {
			as.delReviewById(rId);
			resp.sendRedirect("review.jsp");
			return;
		}
		as.changeReview(newReview, oldReview);
		resp.sendRedirect("review.jsp");
		
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doGet(req,resp);
	}

}
